﻿using Dapper;
using System.Data.SqlClient;
using yunbo.Model.SM;

namespace yunbo.Repositorys.FPMRepositorys
{
    public class WMS_CCPRKXXRepository
    {
        public string data = "Data Source=121.37.93.71;Initial Catalog=FanXingMES;User ID=sa;Password=geili@2025;";

        public int AddWMS_CCPRKXX(WMS_CCPRKXX wMS_CCPRKXX)
        {
            using (SqlConnection connection = new SqlConnection(data))
            {
                string sql = $"insert into wms_cprkxx(cp_code, cprkxx_cpmc, cprkxx_cpfl, cprkxx_cpdw, cprkxx_rksl, cprk_code, cprkxx_code)\r\n" +
                    $"values('{wMS_CCPRKXX.cp_code}','{wMS_CCPRKXX.cprkxx_cpmc}',{wMS_CCPRKXX.cprkxx_cpfl},'{wMS_CCPRKXX.cprkxx_cpdw}','{wMS_CCPRKXX.cprkxx_rksl}','{wMS_CCPRKXX.cprk_code}','{wMS_CCPRKXX.cprkxx_code}')";
                int rs = connection.Execute(sql);
                return rs;
            }
        }

        public List<WMS_CCPRKXX> GetWMS_CCPRKXXes(string code) 
        {
            using (SqlConnection connection = new SqlConnection(data))
            {
                string sql = $@"	select cpxx.[cp_code],cpxx.[cprkxx_cpmc],cpxx.[cprkxx_cpfl],cpxx.[cprkxx_cpdw],cpxx.[cprkxx_rksl],fl.dictionary_name,dw_name,cp.cprk_zt
	                                from [dbo].[wms_cprkxx] cpxx
	                                LEFT JOIN 
	                                [dbo].[dictionary] AS fl
	                                ON fl.dictionary_id=cpxx.[cprkxx_cpfl]
	                                LEFT JOIN 
	                                [dbo].[bd_dw] AS dw
	                                ON dw.[dw_code]=cpxx.[cprkxx_cpdw]
	                                LEFT JOIN 
	                                [dbo].[wms_cprk] AS cp
	                                ON cp.[cprk_code]=cpxx.cprk_code
	                                where cpxx.cprk_code='{code}'";
                List<WMS_CCPRKXX> wMS_CCPRKXXes = connection.Query<WMS_CCPRKXX>(sql).ToList();
                return wMS_CCPRKXXes;
            }
        }
    }
}
